/**
 * PruebaEncriptar.java
 */

 /**
 *  AdSec: Administrador de Secundarias
 *  Copyright (C) 2009 Daniela Ramírez Chaves (dannyrch@gmail.com)
 *  Copyright (C) 2009 Leonel Salazar Valverde (leo87sv@gmail.com)
 *
 *  This file is part of AdSec.
 *  AdSec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AdSec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AdSec.  If not, see <http://www.gnu.org/licenses/>.
 */

package adsec.negocios;

import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class PruebaEncriptar {

    public String encriptarPassword(String password){
        String passEncriptado = "";
        try{
            MessageDigest encriptador = MessageDigest.getInstance("SHA-512");
            //MessageDigest encriptador = MessageDigest.getInstance("MD5");
            encriptador.update(password.getBytes());
            byte [] encriptado = encriptador.digest();
            System.out.println("Encriptado longitud: " +encriptado.length);
            for(int i=0; i < encriptado.length; i++){
                System.out.print(encriptado[i]);
            }
            System.out.println();
            passEncriptado = new String(encriptado);
        }catch(NoSuchAlgorithmException e){
            System.err.println("No existe el algoritmo de encriptación SHA-256 en su sistema");
            e.printStackTrace();
        }
        return passEncriptado;
    }//fin de encriptarPassword

    public static void main(String [] args){
		ControladoraLogin contLogin = new ControladoraLogin();
		byte [] pass1 = contLogin.encriptar("masacasamasacasamasamasacasamasacasamasa");
		//byte [] pass1 = contLogin.encriptar("masacasamasacasamasa");
		String stPass1 = new String(pass1, Charset.forName("UTF-8"));
        
        System.out.println("StPass1 es " + stPass1);
        System.out.println("El array de bytes tiene " + pass1.length);
		for(int i = 0; i < pass1.length; i++){
			System.out.print(pass1[i]);
		}
		System.out.println();
		String desEncriptado = contLogin.desencriptar(pass1);
        System.out.println("Desencrptado sale " + desEncriptado);
    }

	/*
	 public static void main(String [] args){
        PruebaEncriptar prueba = new PruebaEncriptar();
        StringBuffer buffer = new StringBuffer();
        for(int i = 0; i < 10000; i++){
            buffer.append(i);
        }
        System.out.println(prueba.encriptarPassword(buffer.toString()));
        System.out.println(prueba.encriptarPassword("Momo linda"));
        System.out.println(prueba.encriptarPassword("momo linda"));
        System.out.println(prueba.encriptarPassword("password"));
    }
	 */
}
